package duck.manager.impl;

import java.util.List;

import common.CommonDao;

import duck.manager.MessageManager;

public class MessageManagerImpl implements MessageManager {

	public List search(CommonDao cd, String type, String key, String range) throws Exception {
			return cd.loadByQuery(this.search(type, key, range),true);
	}

	public String search(String type, String key, String range) {
		StringBuilder sb = new StringBuilder("from Usermessage ");
		if ((null!=type)&&(!"all".equals(type))) {
			sb.append(" where mtypeid=" + Integer.parseInt(type));
			if (range != null) {
				if (key != null) {
					if ("bt".equals(range)) {
						sb.append(" and mtitle like '%"+key+"%'");
					} else if ("nr".equals(range)) {
						sb.append(" and mcontent  like '%"+key+"%'");
					} else if ("zz".equals(range)) {
						sb.append(" and sender  like '"+key+"%'");
					} else if ("sj".equals(range)) {
						sb.append(" and msendtime like '%"+key+"%'");
					} else {
						sb.append(" and files like '%"+key+"%'");
					}
				}
			} else {
				if (key != null) {
					sb.append("  and mcontent like'%" + key + "%' ");
				}
			}
		}
		return sb.toString();
	}

}
